# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__ = "rbuck"
__date__ = "$Mar 12, 2010 11:04:06 AM$"

import subprocess
from RemoteCommand import *


class FileGrabber:
    """
    Grabs a file from a remote machine
    """
    def __init__(self, srcNode, srcPath, destPath, username):
        print "Init"
        self.srcNode = srcNode
        self.srcPath = srcPath
        self.destPath = destPath
        self.username = username

    def grab(self):
        print "Grabbing file %s from [%s]" %(self.srcPath, self.srcNode)
        command = 'scp'
        src = '%s@%s:%s' % (self.username, self.srcNode, self.srcPath)
        dest = self.destPath
        subprocess.call([command,src,dest])

class FileRemover:
    """
    Removes a file from a remote machine
    """
    def __init__(self, node, path, username):
        print "Init"
        self.node = node
        self.path = path
        self.username = username

    def remove(self):
        print "Removing file %s from [%s]" %(self.path, self.node)
        command = 'rm -rf %s' %(self.path)
        c = Command(self.node,self.username,command)
        c.start()
        c.go.set()
        c.join()

if __name__ == "__main__":
    print "Hello World"
    node = 'mesh10'
    path = '/home/rbuck/out.txt'
    username = 'rbuck'
    
    fg = FileGrabber(node,path,'/home/rbuck/Desktop/',username)
    fg.grab()

    fr = FileRemover(node,path,username)
    fr.remove()
    
